| Conditions | 1 |
| Paths | 2 |
| Total Lines | 171 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | module.exports = function(grunt) { |
||
| 2 | |||
| 3 | var saucelabsBrowsers = [ |
||
| 4 | { |
||
| 5 | // latest chrome |
||
| 6 | browserName: 'googlechrome', |
||
| 7 | platform: 'Windows 10', |
||
| 8 | version: 'latest' |
||
| 9 | }, |
||
| 10 | { |
||
| 11 | // latest firefox |
||
| 12 | browserName: 'firefox', |
||
| 13 | platform: 'Windows 10', |
||
| 14 | version: 'latest' |
||
| 15 | }, |
||
| 16 | { |
||
| 17 | // latest Safari |
||
| 18 | browserName: 'Safari', |
||
| 19 | version: 'latest' |
||
| 20 | }, |
||
| 21 | { |
||
| 22 | // latest edge |
||
| 23 | browserName: 'MicrosoftEdge', |
||
| 24 | platform: 'Windows 10', |
||
| 25 | version: 'latest' |
||
| 26 | } |
||
| 27 | ]; |
||
| 28 | |||
| 29 | grunt.initConfig({ |
||
| 30 | pkg: grunt.file.readJSON('package.json'), |
||
| 31 | connect: { |
||
| 32 | server: { |
||
| 33 | options: { |
||
| 34 | base: '', |
||
| 35 | port: 9999 |
||
| 36 | } |
||
| 37 | } |
||
| 38 | }, |
||
| 39 | |||
| 40 | template: { |
||
| 41 | runtests: { |
||
| 42 | options: { |
||
| 43 | data: { |
||
| 44 | process: { |
||
| 45 | env: process.env |
||
| 46 | } |
||
| 47 | } |
||
| 48 | }, |
||
| 49 | files: { |
||
| 50 | 'test/run-tests.html': ['test/run-tests.tpl.html'] |
||
| 51 | } |
||
| 52 | } |
||
| 53 | }, |
||
| 54 | |||
| 55 | 'saucelabs-mocha': { |
||
| 56 | all: { |
||
| 57 | options: { |
||
| 58 | // username: 'saucelabs-user-name', // if not provided it'll default to ENV SAUCE_USERNAME (if applicable) |
||
| 59 | // key: 'saucelabs-key', // if not provided it'll default to ENV SAUCE_ACCESS_KEY (if applicable) |
||
| 60 | urls: [ |
||
| 61 | // subset of the tests to make sure it doesn't take forever and timeout (on IE and phone simulators) |
||
| 62 | 'http://127.0.0.1:9999/test/run-tests.html' |
||
| 63 | ], |
||
| 64 | browsers: saucelabsBrowsers, |
||
| 65 | build: process.env.TRAVIS_JOB_ID || ('99' + ((new Date).getTime() / 1000).toFixed(0) + (Math.random() * 1000).toFixed(0)), |
||
| 66 | testname: 'bip70 tests', |
||
| 67 | throttled: 2, |
||
| 68 | statusCheckAttempts: 360, // statusCheckAttempts * pollInterval = total time |
||
| 69 | pollInterval: 4000, |
||
| 70 | sauceConfig: { |
||
| 71 | 'command-timeout': 600, |
||
| 72 | 'idle-timeout': 360, |
||
| 73 | 'max-duration': 900, // doesn't seem to take effect |
||
| 74 | 'video-upload-on-pass': true |
||
| 75 | } |
||
| 76 | } |
||
| 77 | } |
||
| 78 | }, |
||
| 79 | |||
| 80 | browserify: { |
||
| 81 | bip70: { |
||
| 82 | options : { |
||
| 83 | browserifyOptions : { |
||
| 84 | standalone: 'bip70' |
||
| 85 | }, |
||
| 86 | transform : ['brfs'] |
||
| 87 | }, |
||
| 88 | src: 'main.js', |
||
| 89 | dest: 'build/bip70.js' |
||
| 90 | }, |
||
| 91 | test: { |
||
| 92 | options : { |
||
| 93 | browserifyOptions : { |
||
| 94 | standalone: 'bip70TEST' |
||
| 95 | }, |
||
| 96 | transform : ['brfs'] |
||
| 97 | }, |
||
| 98 | src: 'test.js', |
||
| 99 | dest: 'build/test.js' |
||
| 100 | } |
||
| 101 | }, |
||
| 102 | |||
| 103 | /* |
||
| 104 | * Javascript uglifying |
||
| 105 | */ |
||
| 106 | uglify : { |
||
| 107 | options: { |
||
| 108 | mangle: { |
||
| 109 | except: ['Buffer', 'BigInteger', 'Point', 'ECPubKey', 'ECKey', 'sha512_asm', 'asm', 'ECPair', 'HDNode'] |
||
| 110 | } |
||
| 111 | }, |
||
| 112 | bip70: { |
||
| 113 | files : { |
||
| 114 | 'build/bip70.min.js' : ['<%= browserify.bip70.dest %>'], |
||
| 115 | } |
||
| 116 | }, |
||
| 117 | test: { |
||
| 118 | files : { |
||
| 119 | 'build/test.min.js' : ['<%= browserify.test.dest %>'] |
||
| 120 | } |
||
| 121 | } |
||
| 122 | }, |
||
| 123 | |||
| 124 | watch : { |
||
| 125 | options : {}, |
||
| 126 | gruntfile : { |
||
| 127 | files : ['Gruntfile.js'], |
||
| 128 | tasks : ['default'] |
||
| 129 | }, |
||
| 130 | browserify : { |
||
| 131 | files : ['main.js', 'lib/*', 'lib/**/*'], |
||
| 132 | tasks : ['browserify:bip70'] |
||
| 133 | }, |
||
| 134 | browserify_test : { |
||
| 135 | files : ['main.js', 'test.js', 'test/*', 'test/**/*', 'lib/*', 'lib/**/*', '!test/run-tests.html'], |
||
| 136 | tasks : ['browserify:test', 'uglify:test', 'template'] |
||
| 137 | } |
||
| 138 | }, |
||
| 139 | |||
| 140 | exec: { |
||
| 141 | build_proto: { |
||
| 142 | cmd: function() { |
||
| 143 | var inputFiles = ['proto/*.proto']; |
||
| 144 | var protoFiles = grunt.file.expand(inputFiles); |
||
| 145 | |||
| 146 | var command = '"./node_modules/.bin/pbjs" -t json '; |
||
| 147 | for (var i = 0; i < protoFiles.length; i++) { |
||
| 148 | command += " " + protoFiles[i] + " "; |
||
| 149 | } |
||
| 150 | |||
| 151 | command += " > lib/protofile.json"; |
||
| 152 | console.log(command); |
||
|
|
|||
| 153 | return command + ' && echo "completed compile"'; |
||
| 154 | } |
||
| 155 | } |
||
| 156 | } |
||
| 157 | }); |
||
| 158 | |||
| 159 | grunt.loadNpmTasks('grunt-browserify'); |
||
| 160 | grunt.loadNpmTasks('grunt-contrib-watch'); |
||
| 161 | grunt.loadNpmTasks('grunt-contrib-uglify'); |
||
| 162 | grunt.loadNpmTasks('grunt-contrib-connect'); |
||
| 163 | grunt.loadNpmTasks('grunt-saucelabs'); |
||
| 164 | grunt.loadNpmTasks('grunt-exec'); |
||
| 165 | grunt.loadNpmTasks('grunt-notify'); |
||
| 166 | grunt.loadNpmTasks('grunt-template'); |
||
| 167 | |||
| 168 | grunt.registerTask('build', ['exec:build_proto', 'browserify', 'uglify:bip70', 'uglify:test', 'template']); |
||
| 169 | grunt.registerTask('test-browser', ['template', 'connect', 'saucelabs-mocha']); |
||
| 170 | grunt.registerTask('default', ['build']); |
||
| 171 | }; |
||
| 172 |